package utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import application.MyApplication;

/**
 * @author 李志培
 *         <p/>
 *         作者信息：嘉应学院1303班
 *         <p/>
 *         创建日期：2016-5-20下午1:18
 *         <p/>
 *         类描述：用户获取跟屏幕有关的数据
 *         <p/>
 *         修改历史：
 */
public class WindowUtils {
    /**
     * 获取屏幕宽度
     * @return
     */
    public static int getWindowWidth() {
        WindowManager WM = (WindowManager) MyApplication.getContext().getSystemService(Context.WINDOW_SERVICE);
        int width = WM.getDefaultDisplay().getWidth();
        return width;
    }
    /**
     * 获取屏幕高度
     */
    public static int getWindowHeight(){
        WindowManager WM = (WindowManager) MyApplication.getContext().getSystemService(Context.WINDOW_SERVICE);
        int height = WM.getDefaultDisplay().getHeight();
        return height;
    }

    /**
     * 隐藏键盘
     * @param view
     */
    public static void hide_keyboard_from(View view) {
        InputMethodManager inputMethodManager = (InputMethodManager) MyApplication.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
    /**
     * 显示键盘
     * @param view
     */
    public static void show_keyboard_from(View view) {
        InputMethodManager inputMethodManager = (InputMethodManager) MyApplication.getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }

}
